package edu.its.dreamteam.web.pages;

import java.util.ArrayList;
import java.util.List;

import org.apache.tapestry.ComponentResources;
import org.apache.tapestry.annotations.Retain;
import org.apache.tapestry.beaneditor.BeanModel;
import org.apache.tapestry.ioc.annotations.Inject;
import org.apache.tapestry.services.BeanModelSource;

import edu.its.dreamteam.daf.beans.Room;
import edu.its.dreamteam.daf.beans.Team;
import edu.its.dreamteam.daf.dao.IRoomDao;
import edu.its.dreamteam.daf.dao.ITeamDao;

public class ViewHighScore {
	@Inject
	private ITeamDao teamDao;
	@Inject
	private IRoomDao roomDao;
	
	@Retain
	private BeanModel teamModel;
	@Inject
	private BeanModelSource teamModelSource;
	@Inject
	private ComponentResources resources;
	
	private List<Team> teamHighList;
	
	private Team team;
	
	
	
	
	
	public List<Team> getTeamHighList() {
		
		if(teamHighList==null){
			teamHighList = new ArrayList<Team>();
			List<Room> roomList = getRoomDao().queryForList("", "");
			for(Room room: roomList){
				Team teamObj = (Team)getTeamDao().getMaxPointRoom(room.getIdRoom());
				if(teamObj!=null){
					teamHighList.add(teamObj);
				}
			}
			
			
		}
		return teamHighList;
	}
	public void setTeamHighList(List<Team> teamHighList) {
		this.teamHighList = teamHighList;
	}
	
	public Team getTeam() {
		return team;
	}
	public void setTeam(Team team) {
		this.team = team;
	}
	
	public ITeamDao getTeamDao() {
		return teamDao;
	}
	public IRoomDao getRoomDao() {
		return roomDao;
	}
	
	public BeanModel getTeamModel() {
		return teamModel;
	}
	
	void pageLoaded(){
		
    	teamModel = teamModelSource.create(Team.class, false, resources);  
    	teamModel.get("idRoom").label("Room");
    	teamModel.get("username").label("Owner");
    	teamModel.remove("idFormation","idTeam");
    	teamModel.reorder("idRoom","username");
    }
	
}
